//
//  ViewController.m
//  MVPDemo
//
//  Created by mobao on 16/6/13.
//  Copyright © 2016年 mobao. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()<MyPresenterDelegate>{
    MyPresenter *presenter;
}

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    //思路：ViewController中关于登录的操作放到MyPresenter中
    //     MyPresenter执行登录操作，登录成功或者失败后的相关操作，交给ViewController中执行
    //     也就是如下关于MyPresenterDelegate的三个方法。
    //     所以这里是Presenter委托ViewController实现代理方法。
    
    //实例化Presenter对象，将页面的传给Presenter
    presenter = [[MyPresenter alloc]initWithViewController:self];
    presenter.myPresenterDelegate = self;
 
}

//登录事件
- (IBAction)MyBtnClick:(UIButton *)sender{
    [presenter loginWithAccount:_accountTextF.text password:_passwordTextF.text];
}

#pragma mark -MyPresenterDelegate
-(void)logining:(NSString *)info{
    _infoLabel.text = info;
}

-(void)loginSuccess:(NSString *)info{
    _infoLabel.text = info;
}

-(void)loginFailure:(NSString *)info{
    _infoLabel.text = info;
}

//触摸空白地方，键盘隐藏
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [_accountTextF resignFirstResponder];
    [_passwordTextF resignFirstResponder];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
